// pages/detail/detail.js
Page({
    data: {
        banners:[
            {
                id:1,
                imageurl:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Flmg.jj20.com%2Fup%2Fallimg%2F1115%2F101021113337%2F211010113337-6-1200.jpg&refer=http%3A%2F%2Flmg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1673070911&t=2a20ecbb9ddf9d2af7cae8f6a547707e"
            },
            {
                id:2,
                imageurl:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg1.doubanio.com%2Fview%2Fgroup_topic%2Fl%2Fpublic%2Fp484146349.jpg&refer=http%3A%2F%2Fimg1.doubanio.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1673070871&t=3160f248f4ba3e1ea01cc24f22d5d2fb"
            },
            {
                id:3,
                imageurl:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic_source%2Fca%2F5d%2F0d%2Fca5d0df7a182802fe7798e29d769cca8.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1673070835&t=bc9fcecbaa41c3c3c03fa6ecc03f35e8"
            }
        ],
        book_detail:{
            bookAuthor: "",
            bookDesc: "",
            bookId: "",
            bookName: "",
            bookPrice: "",
            bookTypeId: "",
            createTime: "",
            isNew: null,
            isRm: null,
            updateTime: "",
        },
        isLike: true,
        // banner
        imgUrls: [
            "https://img.alicdn.com/imgextra/i3/2776335350/O1CN01z5Goct1pOLfBpq10F_!!2776335350.jpg",
            "https://img.alicdn.com/imgextra/i1/2776335350/O1CN01DYu7Yq1pOLf7NR4Qg_!!2776335350.jpg",
            "https://img.alicdn.com/imgextra/i3/2776335350/O1CN01BCfOAe1pOLfBpqU7d_!!2776335350.jpg",
            "https://img.alicdn.com/imgextra/i3/2776335350/O1CN01NIOjXl1pOLfCwXMLX_!!2776335350.jpg",
            "https://img.alicdn.com/imgextra/i3/2776335350/O1CN01g2SHHJ1pOLfBprpIz_!!2776335350.jpg",
        ],
        indicatorDots: true, //是否显示面板指示点
        autoplay: true, //是否自动切换
        interval: 3000, //自动切换时间间隔,3s
        duration: 1000, //	滑动动画时长1s
    
        // 商品详情介绍
        detailImg: [
            "https://img.alicdn.com/imgextra/i3/2776335350/O1CN01z5Goct1pOLfBpq10F_!!2776335350.jpg",
            "https://img.alicdn.com/imgextra/i3/2776335350/O1CN01M1D2XT1pOLfDfeaIm_!!2776335350.jpg",
            "https://img.alicdn.com/imgextra/i1/2776335350/O1CN01dQ5UZm1pOLfBprI1N_!!2776335350.jpg",
            "https://img.alicdn.com/imgextra/i1/2776335350/O1CN015JMDss1pOLecc2pDw_!!2776335350.jpg",
            "https://img.alicdn.com/imgextra/i4/2776335350/O1CN01hOxOFe1pOLeYjTl6V_!!2776335350.jpg",
            "https://img.alicdn.com/imgextra/i1/2776335350/O1CN01AyHpAh1pOLed4tHsI_!!2776335350.jpg",
            "https://img.alicdn.com/imgextra/i4/2776335350/O1CN01tSJ21F1pOLeeAfhgh_!!2776335350.jpg"
        ],


        
    },
    //预览图片
    previewImage: function (e) {
    var current = e.target.dataset.src;

    wx.previewImage({
        current: current, // 当前显示图片的http链接  
        urls: this.data.imgUrls // 需要预览的图片http链接列表  
    })
    },

    onLoad(options) {
        var _this=this;
        let id = options.id;
        console.log(id)
        wx.showLoading({
            title: '加载中',
            mask:true
        })
        wx.request({
            url: 'http://43.139.97.111:8080/books/queryById?id=' + id,        
            header: {
                'content-type': 'application/json' // 默认值
            },
            success (res) {
                console.log(res.data);
                if(res.statusCode==200){
                    _this.setData({
                        book_detail:res.data.data,
                    });
                }
                wx.hideLoading()
            }
        })
    },

    //跳转购物车
    jumpCart() {
        // 给全局变量添加一个参数 book_detail
       wx.switchTab({
         url: '/pages/shoppingCart/shoppingCart'
       })
    },

    addToCart(){
        wx.request({
            url: 'http://43.139.97.111:8080/cartItem/insert',        
            header: {
                'content-type': 'application/json' // 默认值
            },
            data: {
                bookId: this.data.book_detail.bookId,
                bookNumber: 1,
                cartItemId: this.data.book_detail.cartItemId,
                userId: 22,
            },
            method: 'POST',
            success (res) {
                console.log(res.data);
                wx.hideLoading()
            }
        })
    },

    // 立即购买
    immeBuy() {
        wx.navigateTo({
            // url: '/pages/pay/pay?amount=' + that.data.totalMoney
            url: '/pages/pay/pay?paylist=' + JSON.stringify(this.data.book_detail)+'&totalMoney='+this.data.book_detail.bookPrice
        });
    },
})
  






